package com.example.hosptial.repository;

import com.example.hosptial.model.enity.Doctor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DoctorRepository extends JpaRepository<Doctor, String> {

    // 根据医生ID查找
    Doctor findByDoctorId(String doctorId);

    // 检查医生ID是否存在
    boolean existsByDoctorId(String doctorId);

    // 根据科室ID查询医生列表
    List<Doctor> findByDepartmentDeptId(Integer deptId);

    // 更新医生信息（使用存储过程）
    @Procedure(name = "UpdateDoctorPhoneAndPassword")
    void updateDoctorPhoneAndPassword(
        @Param("inputDoctorId") String doctorId,
        @Param("newDoctorPhone") String newPhone,
        @Param("newDoctorPassword") String newPassword
    );

    // 自定义更新方法
    @Modifying
    @Query("UPDATE Doctor d SET d.doctorPhone = :phone, d.doctorPassword = :password WHERE d.doctorId = :doctorId")
    int updateDoctorInfo(@Param("doctorId") String doctorId,
                        @Param("phone") String phone,
                        @Param("password") String password);

    boolean existsByDoctorIdCard(String doctorIdCard);

}